#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : AutomaticTestProgram 
@File    : api_log_decorator.py
@IDE     : PyCharm 
@Author  : Mario
@Date    : 2022/11/28 17:13 
@Describe: 接口请求日志装饰器
"""
from functools import wraps
from utils.log.log_control import LogHandler

logger = LogHandler().get_logger()


def api_log_decorator(switch: bool):
    """
    接口请求日志装饰器
    @param switch: 日志开关
    @return:
    """

    def decorator(func):
        @wraps(func)
        def swapper(*args, **kwargs):
            res = func(*args, **kwargs)
            if switch:
                if res is not None:
                    print(args)
                    print(res)
                    return res
                else:
                    return res
            else:
                return res

        return swapper

    return decorator
